#include"utils.h"



static ssize_t ReceiveDatagramFromSocket(JNIEnv* env, jobject obj, int sd,struct sockaddr_in* address, char* buffer, size_t bufferSize);


static ssize_t ReceiveDatagramFromSocket(JNIEnv* env, jobject obj, int sd,
		struct sockaddr_in* address, char* buffer, size_t bufferSize) {
	socklen_t addressLength = sizeof(struct sockaddr_in);
	struct timeval tv_out;
	tv_out.tv_sec = 5; //等待10秒
	tv_out.tv_usec = 0;
	setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, &tv_out, sizeof(tv_out));
	ssize_t recvSize = recvfrom(sd, buffer, bufferSize, 0,
			(struct sockaddr*) address, &addressLength);
	if (-1 == recvSize) {
		return  -1;
	} else {
		buffer[recvSize] = NULL;
		if (recvSize > 0) {

		}
	}
	return recvSize;
}

static ssize_t SendDatagramToSocket(JNIEnv* env, jobject obj, int sd,
		const struct sockaddr_in* address, const char* buffer,
		size_t bufferSize) {

	ssize_t sentSize = sendto(sd, buffer, bufferSize, 0,
			(const sockaddr*) address, sizeof(struct sockaddr_in));
	if (-1 == sentSize) {

	}

	return sentSize;
}
